
# Makefile - make rules for systems/bcm4704/bcm4704
#
# modification history
# --------------------
#
# DESCRIPTION
# This file contains rules for building VxWorks for the BCM 4702.
#  
#  This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
#  the contents of this file may not be disclosed to third parties, copied or
#  duplicated in any form, in whole or in part, without the prior written
#  permission of Broadcom Corporation.
#  
##################################################################

CPU             = MIPS32
ifeq ($(VX_TARGET_BIG_ENDIAN),1)
TOOL            = sfgnu
SFCOMMON_BCM33XX = sfcommon_rc32xxx
else
TOOL            = sfgnule
SFCOMMON_BCM33XX = sfcommonle_rc32xxx
endif


TGT_DIR=$(WIND_BASE)/target

include $(TGT_DIR)/h/make/defs.bsp
include $(TGT_DIR)/h/make/make.$(CPU)$(TOOL)
include $(TGT_DIR)/h/make/defs.$(WIND_HOST_TYPE)

CONFIG_ALL=$(SRC_DIR)/all
DRV_DIR=../../../../drv

# uncomment it for QT 
#ADDED_CFLAGS   += -DQUICK_TURN

## Only redefine make definitions below this point, or your definitions will
## be overwritten by the makefile stubs above.

#Disable compiler optimization DEBUG DEBUG
#C_OPTIM_NORMAL = -O0
#CC_OPTIM_TARGET = -O0


# Add some options to CFLAGS for drivers and platform
CFLAGS   += -DBROADCOM_BSP -DVXWORKS
#CFLAGS   += -DBCM56218_UART_BUSY_WRITE_PROTECT

ifeq ($(DEVICE),BCM56018)
CFLAGS += -DBCM56018
EXTRA_DEFINE += -DBCM56018
else
ifeq ($(DEVICE),BCM56218P48)
CFLAGS += -DBCM56218P48
EXTRA_DEFINE += -DBCM56218P48
else
ifeq ($(DEVICE),BCM56214)
CFLAGS += -DBCM56214
EXTRA_DEFINE += -DBCM56214
else
ifeq ($(DEVICE),BCM56014)
CFLAGS += -DBCM56014
EXTRA_DEFINE += -DBCM56014
else
CFLAGS += -DBCM56218
EXTRA_DEFINE += -DBCM56218
endif
endif
endif
endif

ifdef CONSOLE_BAUD_RATE_OVERRIDE
CFLAGS += -DCONSOLE_BAUD_RATE_OVERRIDE=${CONSOLE_BAUD_RATE_OVERRIDE}
endif

ifeq ($(BCM_END_DRV),1)
CFLAGS += -DBCM_END_DRV
endif
# uncomment for Qt
#CFLAGS  += -DQUICK_TURN

ifeq ($(WIND_HOST_TYPE),x86-linux)
LDFLAGS += -T $(WIND_BASE)/host/sun4-solaris2/mips-wrs-vxworks/lib/ldscripts/vxw5ebmip.x
endif
CFLAGS += -DMBZ

TARGET_DIR      = bcm56218
VENDOR          = Broadcom
BOARD           = Model-1

#EXTRA_DEFINE     =-DCPU_VAR=RC32364 -DBROADCOM_BSP -DTARGETOS_vxWorks -Dvxworks 

# For BCM4704A0/A1, due to a chip erratum the define -DPATCH_INT_STUBS must
# be used.  This patches the VxWorks MIPS interrupt stubs at run-time to
# work around the erratum.  This workaround is ONLY compatible with
# VxWorks 5.4.1 libraries.  For BCM4704A2, the workaround is not needed
# and -DPATCH_INT_STUBS define should be not be used.

ifeq ($(VX_VERSION),542)
CFLAGS     += -DCPU_VAR=RC32364 -DTARGETOS_vxWorks -Dvxworks -DPATCH_INT_STUBS -DVX_VERSION=${VX_VERSION}
else
CFLAGS     += -DCPU_VAR=RC32364 -DTARGETOS_vxWorks -Dvxworks -DVX_VERSION=${VX_VERSION}
endif

################################################################## 
## Only redefine make definitions below this point, or your 
## definitions will be overwritten by the makefile stubs above.
################################################################## 

################################################################## 
# The constants ROM_TEXT_ADRS, ROM_SIZE, RAM_LOW_ADRS and
# RAM_HIGH_ADRS are defined in config.h and MakeSkel.
# All definitions for these constants must be identical.
################################################################## 

ROM_TEXT_ADRS           = bfc00000      # ROM entry address
ROM_SIZE                = 00080000      # Number of bytes of ROM space
RAM_LOW_ADRS            = 80008000      # RAM text/data address
RAM_HIGH_ADRS           = 82c00000

#This macro LD_LINK_PATH is for link path
ifeq ($(VX_VERSION),55)
LD_LINK_PATH    = $(LD_LINK_PATH_EXTRA) \
		  -L$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL)
LD_LINK_PATH_EXTRA = -L$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL)$(CPU_VARIANT)
endif

# Broadcom BCM56XXX Front-panel Gigabit Ethernet Driver
BCM_END_DRV_SRC = $(SRC_DIR)/../../bcmdrv
BCM_END_DRV_OBJS    = dmaOps.o dmaRx.o dmaTx.o linkscan.o netdrv.o phy5464.o salIntf.o systemInit.o
ifeq ($(VX_TARGET_BIG_ENDIAN),1)
BCM_END_DRV_FLAGS   = -DVXWORKS -DICS -DRAPTOR -DBOOTROM_DEBUG -DBE_HOST=1 -DPOLLING_MODE
else
BCM_END_DRV_FLAGS   = -DVXWORKS -DICS -DRAPTOR -DBOOTROM_DEBUG -DBE_HOST=0 -DPOLLING_MODE
endif

%.o : $(BCM_END_DRV_SRC)/%.c
	$(CC) -I$(SRC_DIR) -I$(BCM_END_DRV_SRC) $(CFLAGS) $(BCM_END_DRV_FLAGS) -c $< -o $@

#NVRAM_OBJS =
NVRAM_OBJS = nvramstubs.o 

bsplib_clean:
	$(RM) *.o
	$(RM) *.a

# Add driver objects to MACH_EXTRA for building bootrom and ram image


MACH_EXTRA = srecLoad.o ns16550Sio.o \
                cacheLib.o cacheALib.o platform.o \
                sysSerial.o vx_osl.o \
                bcmutils.o \
		flash29l160DrvLib.o flash28f320DrvLib.o \
		flashDrvLib.o flashFsLib.o flash29GL256DrvLib.o \
                ftpXfer2.o \
                $(NVRAM_OBJS) \
                $(WRS_OBJS)

ifeq ($(BCM_END_DRV),1)
MACH_EXTRA += $(BCM_END_DRV_OBJS)
CFLAGS += -DBCM_END_DRV
endif

ifeq ($(VX_VERSION),55)

override LIB_EXTRA	+= $(TGT_DIR)/lib/mips/MIPS32/$(SFCOMMON_BCM33XX)/libarch.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libcommoncc.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libdcc.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libdrv.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libgcc.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libnet.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libos.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/librpc.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libusb.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libwdb.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libwind.a \
	$(TGT_DIR)/lib/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libwindview.a
else
ifeq ($(VX_VERSION),542)
else
endif
endif

# uncomment below for map file
LDFLAGS += -X -N -Map $@.map

################################################################## 
## Only redefine make definitions above this point, or the expansion of
## makefile target dependencies may be incorrect.
################################################################## 


include $(TGT_DIR)/h/make/rules.bsp
include $(TGT_DIR)/h/make/rules.$(WIND_HOST_TYPE)

HEXBIN=$(BIN_DIR)/$(OBJCPY)$(TOOLENV) -I srec -O binary

bootrom_swap$(bcm_suffix).hex:
	${HEXBIN} bootrom$(bcm_suffix).hex bootrom$(bcm_suffix).bin
ifeq ($(HOSTTYPE),Windows2000PC)
	${CP} bootrom$(bcm_suffix).hex ../bootrom$(bcm_suffix).hex
else
	${CP} ${SRC_DIR}/bootrom$(bcm_suffix).hex ../bootrom$(bcm_suffix).hex
	${CP} ${SRC_DIR}/bootrom$(bcm_suffix).bin ../bootrom$(bcm_suffix).bin
endif
#	rm bootrom$(bcm_suffix).bin bootrom_swap$(bcm_suffix).bin

ifeq ($(HOSTTYPE),Windows2000PC)
MY_NM		=	ccmips

usrConfig_st.o : depend.$(BSP_NAME) $(USRCONFIG) usrConfig.o
	- @ $(RM) $@
	$(CP) .\all\usrConfig.c usrConfig_st.c
	$(CC) $(OPTION_OBJECT_ONLY) $(CFLAGS) -DSTANDALONE usrConfig_st.c
	- @ $(RM) usrConfig_st.c


vxWorks.st : depend.$(BSP_NAME) usrConfig_st.o dataSegPad.o \
		$(MACH_DEP) $(LDDEPS) $(patsubst -l%,lib%.a,$(LIBS)) \
		$(CC_LIB)
	- @ $(RM) $@ 
	- @ $(RM) symTbl.c 
	- @ $(RM) symTbl.o 
	- @ $(RM) tmp.o 
	- @ $(RM) tmp.2
	- @ $(RM) version.o
	- @ $(RM) ctdt.c ctdt.o
	$(CC) $(OPTION_OBJECT_ONLY) $(CFLAGS) -o version.o $(CONFIG_ALL)/version.c
	$(LD_PARTIAL) -o tmp.o dataSegPad.o $(MACH_DEP) \
	    usrConfig_st.o version.o $(LD_PARTIAL_START_GROUP) $(LD_LINK_PATH) \
	    $(LIBS) $(LD_PARTIAL_END_GROUP) $(CC_LIB)
	$(MY_NM) tmp.o | $(MUNCH) >ctdt.c
	$(MAKE) CC_COMPILER="$(OPTION_DOLLAR_SYMBOLS)" ctdt.o
	$(CP) tmp.o tmp.2
	$(LDOUT_SYMS) tmp.o
	$(MKSYMTBL) tmp.o symTbl.c
	$(COMPILE_SYMTBL) symTbl.c
	$(LD) $(LDFLAGS) $(LD_ENTRY_OPT) $(SYS_ENTRY) $(LD_LOW_FLAGS) \
	    -o $@ dataSegPad.o $(MACH_DEP) \
	    usrConfig_st.o version.o $(LD_LINK_PATH) -( \
	    $(LIBS) -) $(CC_LIB) symTbl.o ctdt.o $(LD_SCRIPT_RAM) -Map vxWorksSt.map
	$(LDOUT_SYMS) $@
	$(LDOUT_CONV) $@
	$(VXSIZEPROG) -v $(RAM_HIGH_ADRS) $(RAM_LOW_ADRS) vxWorks.st
	- @ $(RM) tmp.?
endif
